/**
 *
 */
package com.moogene.android.engine.animlite;

import com.moogene.android.engine.util.MooMath;

/**
 * @author 28849218
 *
 */
public class VibrateAnim extends Anime {

    private int scaleX;
    private int scaleY;
    private int duration;
    private int curScaleX;
    private int curScaleY;
    private int curDuration;

    /**
     * @param drawableWrapper
     */
    VibrateAnim(DrawableWrapper drawableWrapper) {
        super(drawableWrapper);
    }
    public void start(int scaleX, int scaleY, int duration) {
        start();
        this.scaleX = scaleX;
        this.scaleY = scaleY;
        this.duration = duration;
        this.curScaleX = scaleX >> 2;
        this.curScaleY = scaleY >> 2;
        this.curDuration = curDuration >> 2;
    }

    boolean nextFrame() {
        if (!super.nextFrame()) {
            return false;
        }
        duration --;
        curDuration --;
        if(duration == 0){
            stop();
            return false;
        }
        if(curDuration == 0){
            curDuration = curDuration >> 2;
            curScaleX += scaleX >> 2;
            curScaleY += scaleY >> 2;
        }
        int x = MooMath.random(-curScaleX, curScaleX);
        int y = MooMath.random(-curScaleY, curScaleY);
        drawableWrapper.setViabrate(x, y);
        return true;
    }
}
